const { response } = require("express");
let express = require("express");
let path = require("path");

// 创建router对象

let router = express.Router();

// 在router对象上面添加路由

//在router对象上面添加路由
router.get("/",(request,response) => {
    // send相当于 setHeader（） 和 end（） 的封装
    response.send("<h1>欢迎访问首页</h1>");
})

router.get("/game",(request,response) => {
    response.send("<h1>游戏频道</h1>");
})

// // 图片
// router.get("/1.jpg",(request,response) => {
//     response.sendFile(path.resolve("./public/1.jpg"));
// })
// // css
// router.get("/login.css",(request,response) => {
//     response.sendFile(path.resolve("./public/login.css"));
// })

// 登录
router.get("/login",(request,response) => {

    response.sendFile(path.resolve("./views/login.html"));
})



// 学号
router.get("/student/:num",(request,response) => {
    let {num} = request.params;
    response.send("<h1>" + num + "号学生信息查看</h1>")
})

// 书籍(第一种方式)
router.get("/book/:b/author/:a",(request,response) => {
    let {b,a} = request.params;
    response.send(`<h1>书籍：${b}作者：${a}</h1>`);
})

// 书籍（第二种方式）
router.get("/book",(request,response) => {
    console.log(request.query);
    let {book,author} = request.query;
    response.send(`<h1>书籍：${book}作者：${author}</h1>`);
})
router.get("/dologin",(request,response) => {
    let {username,password} = request.query;
    response.send(`<h1>账号${username}密码${password}</h1>`);
})


// 向外暴露router
module.exports = router;